package com.study.system.course.controller;

import com.study.system.course.config.CourseMQConfig;
import com.study.system.course.service.CourseService;
import com.study.system.entity.Course;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Reader;
import java.util.List;

/**
 * 课程控制器
 */
@RestController
public class CourseController {

    @Resource
    private CourseService courseService;

    @GetMapping("/courses")
    public ResponseEntity<List<Course>> getAllCourses(){
        List<Course> allCourses = courseService.getAllCourses();
        return ResponseEntity.ok(allCourses);
    }

    @Resource
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/sendMessage")
    public String sendMessage(String course,String key){
        rabbitTemplate.convertAndSend(CourseMQConfig.COURSE_EXCHANGE,key,course);
        return "OK";
    }

    @RequestMapping("/hello")
    public String hello(){
        return "Hello";
    }
}